# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=LibRaw
pkgbase=mingw-w64-libraw
pkgname="${MINGW_PACKAGE_PREFIX}-libraw"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.20.0
pkgrel=1
pkgdesc="Library for reading RAW files obtained from digital photo cameras (mingw-w64)"
arch=('any')
url="https://www.libraw.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-jasper"
         "${MINGW_PACKAGE_PREFIX}-lcms2"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=("https://www.libraw.org/data/${_realname}-${pkgver}.tar.gz"
        "LibRaw_wsock32.patch"
        "LibRaw_obsolete-macros.patch")
sha256sums=('1f0a383da2ce9f409087facd28261decbf6be72cc90c78cd003b0766e4d694a3'
            '4bd077917fb8f37fa736e3a8bf32fabe3df3ff5438b684acbb5adff8a6c2a73b'
            '4a31c0ee066f43915beff6f7959b6b2cd246d390720df379bfc047d4cedb6a8f')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/LibRaw_wsock32.patch"
  patch -Np1 -i "${srcdir}/LibRaw_obsolete-macros.patch"

  autoreconf -ifv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  CPPFLAGS+=" -DLIBRAW_NODLL"
  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
